/*
 * Copyright 2022-2029 heshuixing(https://gitee.com/heshuixing)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mercury.ec.framework.air.core.client.impl.skyecho;

import com.mercury.ec.framework.air.core.client.dto.order.cancel.AirOrderCancelReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.cancel.AirOrderCancelRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.create.AirOrderCreateReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.create.AirOrderCreateRespDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssueReqDTO;
import com.mercury.ec.framework.air.core.client.dto.order.issue.AirOrderIssueRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.detr.AirDetrReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.detr.AirDetrRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.flight.AirSearchFlightReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.flight.AirSearchFlightRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.pat.AirPatReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.pat.AirPatRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.patex.AirPatexReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.patex.AirPatexRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.price.AirSearchPriceReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.price.AirSearchPriceRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.raw.AirRawReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.raw.AirRawRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rt.AirRtRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rtkt.AirRtktReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.rtkt.AirRtktRespDTO;
import com.mercury.ec.framework.air.core.client.dto.search.xsfsi.AirXsfsiReqDTO;
import com.mercury.ec.framework.air.core.client.dto.search.xsfsi.AirXsfsiRespDTO;
import com.mercury.ec.framework.air.core.client.impl.AbstractAirClient;
import com.mercury.ec.framework.air.core.client.impl.skyecho.convert.SkyechoConvert;
import com.mercury.ec.framework.air.core.client.impl.skyecho.dto.SkyechoCommonRespDTO;
import com.mercury.ec.framework.air.core.client.impl.skyecho.dto.searchflight.SkyechoSearchFlightRespDTO;
import com.mercury.ec.framework.air.core.client.impl.skyecho.execute.DefaultSkyechoAirExecute;
import com.mercury.ec.framework.air.core.client.impl.skyecho.execute.SkyechoAirExecute;
import com.mercury.ec.framework.air.core.property.AirChannelProperties;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 小太阳机票客户端
 *
 * @author hesx
 */
public class SkyechoAirClient extends AbstractAirClient {

    private SkyechoAirExecute skyechoAirExecute;

    public SkyechoAirClient(AirChannelProperties properties) {
        super(properties);
    }

    @Override
    protected void doInit() {
        skyechoAirExecute = new DefaultSkyechoAirExecute();
    }

    @Override
    public AirSearchFlightRespDTO getFlight(AirSearchFlightReqDTO reqDTO) {
        SkyechoCommonRespDTO<SkyechoSearchFlightRespDTO> result = skyechoAirExecute.execute(properties.getUrl(), properties.getApiAccount(), properties.getApiPassword(), SkyechoConvert.convertSkyechoSearchFlightReqDTO(reqDTO), SkyechoSearchFlightRespDTO.class);
        if (result.getCode() == 0) {
            return SkyechoConvert.convertAirSearchFlightRespDTO(properties.getId(), properties.getName(), properties.getChannelType(), reqDTO.getCustomerAgreementType(), result.getData());
        }
        AirSearchFlightRespDTO airSearchFlightRespDTO = new AirSearchFlightRespDTO();
        airSearchFlightRespDTO.setFlights(new ArrayList<>());
        return airSearchFlightRespDTO;
    }

    @Override
    public AirSearchPriceRespDTO getPrice(AirSearchPriceReqDTO reqDTO) {
        SkyechoCommonRespDTO<SkyechoSearchFlightRespDTO> result = skyechoAirExecute.execute(properties.getUrl(), properties.getApiAccount(), properties.getApiPassword(), SkyechoConvert.convertSkyechoSearchFlightReqDTO(reqDTO), SkyechoSearchFlightRespDTO.class);
        if (result.getCode() == 0) {
            return SkyechoConvert.convertAirSearchPriceRespDTO(properties.getId(), properties.getName(), properties.getChannelType(), reqDTO.getAirlineNo(), reqDTO.getFlightNo(), reqDTO.getCustomerAgreementType(), result.getData());
        }
        AirSearchPriceRespDTO airSearchPriceRespDTO = new AirSearchPriceRespDTO();
        airSearchPriceRespDTO.setPrices(new ArrayList<>());
        return airSearchPriceRespDTO;
    }

    @Override
    public AirRtRespDTO rt(AirRtReqDTO reqDTO) {
        return null;
    }

    @Override
    public List<AirPatRespDTO> pat(AirPatReqDTO reqDTO) {
        return null;
    }

    @Override
    public List<AirPatexRespDTO> patex(AirPatexReqDTO reqDTO) {
        return null;
    }

    @Override
    public List<AirXsfsiRespDTO> xsfsi(AirXsfsiReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirDetrRespDTO detr(AirDetrReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirRawRespDTO raw(AirRawReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirRtktRespDTO rtkt(AirRtktReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirOrderCreateRespDTO createOrder(AirOrderCreateReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirOrderCancelRespDTO cancelOrder(AirOrderCancelReqDTO reqDTO) {
        return null;
    }

    @Override
    public AirOrderIssueRespDTO issueOrder(AirOrderIssueReqDTO reqDTO) {
        return null;
    }
}
